package telebase;

import java.awt.Component;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeCellRenderer;

public class ContactsEditViewTreeRenderer extends JPanel implements TreeCellRenderer {

    public ContactsEditViewTreeRenderer() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel4 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setBackground(javax.swing.UIManager.getDefaults().getColor("Tree.background"));

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/telebase/resources/contfolderroot48.png"))); // NOI18N

        jLabel1.setFont(jLabel1.getFont().deriveFont(jLabel1.getFont().getStyle() & ~java.awt.Font.BOLD));
        jLabel1.setText("text1");

        jLabel2.setFont(jLabel2.getFont().deriveFont((jLabel2.getFont().getStyle() | java.awt.Font.ITALIC) & ~java.awt.Font.BOLD));
        jLabel2.setText("text2");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addContainerGap(14, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2))
                    .addComponent(jLabel4))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    // End of variables declaration//GEN-END:variables

    @Override
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;

        if (node.getUserObject().getClass().equals(WorkObj.class)) {
            WorkObj wo = (WorkObj) node.getUserObject();
            if (leaf) {
                if (wo.getContname() == null) {
                    jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/telebase/resources/contactempty48.png")));
                    jLabel1.setFont(jLabel1.getFont().deriveFont(jLabel1.getFont().getStyle() & ~java.awt.Font.BOLD));
                    jLabel1.setText(wo.getWorkname());
                    jLabel2.setText("");
                } else {
                    jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/telebase/resources/contact48.png")));
                    jLabel1.setFont(jLabel1.getFont().deriveFont(jLabel1.getFont().getStyle() & ~java.awt.Font.BOLD));
                    jLabel1.setText(wo.getWorkname());
                    jLabel2.setText(wo.getContname());
                }

            } else {
                jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/telebase/resources/contfolder48.png")));
                jLabel1.setFont(jLabel1.getFont().deriveFont(jLabel1.getFont().getStyle() | java.awt.Font.BOLD));
                jLabel1.setText(wo.getWorkname());
                jLabel2.setText("");
            }
        } else {
            jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/telebase/resources/contfolderroot48.png")));
            jLabel1.setText(value.toString());
            jLabel2.setText("");
        }

        if (selected) {
            setBackground(javax.swing.UIManager.getDefaults().getColor("Tree.selectionBackground"));
        } else {
            setBackground(javax.swing.UIManager.getDefaults().getColor("Tree.background"));
        }

        return this;
    }
}
